package model.model02.demo03;

import com.model.model02.demo03.context.CashContext;

import java.util.Scanner;

public class Main {

    static double allTotal = 0.0;

    public static void main(String[] args) {
        CashContext context;
        do {
            double total = 0.0;
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入单价: ");
            double unitPrice = sc.nextDouble();

            System.out.print("请输入数量: ");
            int number = sc.nextInt();

            System.out.print("请输入折扣(0: 正常收费, 1: 满300返100, 2: 打8折): ");
            int discount = sc.nextInt();

            context = new CashContext(discount);
            total = context.getResult(unitPrice * number);

            System.out.println("单价: " + unitPrice + ", 数量: " + number + ", 合计: " + total);

            allTotal += total;

            System.out.println("是否退出购物(0: 退出, 1: 继续购物): ");
            int flag = sc.nextInt();
            if (flag == 0) {
                break;
            }
        } while (true);

        System.out.println("本次购物结束,总计: " + allTotal);
    }

}
